package org.csu.myPetStore.persistence.impl;

import org.csu.myPetStore.domain.CloseSource;
import org.csu.myPetStore.persistence.DBUtil;
import org.csu.myPetStore.persistence.LogcatDAO;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class LocatDAOImpl implements LogcatDAO {

    private static final String InsertLogCat = "INSERT INTO logcat(username,operator) VALUES(?,?)";

    @Override
    public void InsertLogCat(String username, String operator) {
        try {
            Connection connection = DBUtil.getConnection();
            PreparedStatement preparedStatement = connection.prepareStatement(InsertLogCat);
            preparedStatement.setString(1,username);
            preparedStatement.setString(2,operator);
            int result = preparedStatement.executeUpdate();
            if(result == 1)
                System.out.println("插入logcat成功");

            CloseSource closeSource = new CloseSource();
            closeSource.closeSource(connection,preparedStatement,null,null);

        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
